// var i;
// var $bossComming_UIBindings = require("./BossComming_UIBindings");
// var $resKeeper = require("./ResKeeper");
// var $audioManager = require("./AudioManager");
// var $bundleConfig = require("./BundleConfig");
// var d = cc._decorator;
// var p = d.ccclass;
// var h = d.property;
// var f = d.inspector;
// var g = (function (e) {
//     function t() {
//         var t = (null !== e && e.apply(this, arguments)) || this;
//         t.auto_ui = null;
//         return t;
//     }
//     __extends(t, e);
//     t.prototype.onLoad = function () {
//         this.StartTween();
//     };
//     t.prototype.StartTween = function () {
//         var e = this.auto_ui;
//         e.node_headNode.runAction(
//             cc.repeatForever(
//                 cc.sequence(
//                     cc.spawn(cc.scaleTo(1, 1.1, 1.1), cc.fadeTo(1, 180)),
//                     cc.spawn(cc.scaleTo(1, 1, 1), cc.fadeTo(1, 255))
//                 )
//             )
//         );
//         e.node_boneNode.runAction(
//             cc.repeatForever(
//                 cc.sequence(cc.rotateTo(0.125, 15), cc.rotateTo(0.25, -15), cc.rotateTo(0.125, 0), cc.delayTime(1))
//             )
//         );
//         e.node_ziNode.runAction(cc.repeatForever(cc.sequence(cc.scaleTo(1, 1.1, 1.1), cc.scaleTo(1, 1, 1))));
//         var t = 0;
//         e.node_fireNode.runAction(
//             cc.repeatForever(
//                 cc.sequence(
//                     cc.callFunc(function () {
//                         e.node_fireNode.children.forEach(function (o, n) {
//                             o.active = n == t % e.node_fireNode.childrenCount;
//                         });
//                         t++;
//                     }),
//                     cc.delayTime(0.25)
//                 )
//             )
//         );
//     };
//     t.prototype.onEnable = function () {};
//     t.prototype.onDisable = function () {};
//     t.prototype.showAni = function () {
//         var e = this;
//         if (!this.node.children[0].active) {
//             $audioManager.AudioMgr.playEffect("sound/bossComming", !1, $bundleConfig.BundleNames.Game);
//             this.node.children[0].active = !0;
//             var t = this.auto_ui.node_tiaoNode;
//             t.setPosition(7, 101);
//             t.opacity = 255;
//             t.stopAllActions();
//             t.runAction(
//                 cc.sequence(
//                     cc.repeat(
//                         cc.sequence(
//                             cc.moveTo(0.1, t.x, t.y + 10),
//                             cc.moveTo(0.2, t.x, t.y - 15),
//                             cc.moveTo(0.1, t.x, t.y)
//                         ),
//                         3
//                     ),
//                     cc.fadeOut(1),
//                     cc.callFunc(function () {
//                         e.node.children[0].active = !1;
//                     })
//                 )
//             );
//         }
//     };
//     __decorate([h($bossComming_UIBindings.default)], t.prototype, "auto_ui", void 0);
//     return __decorate([p], t);
// })($resKeeper.default);
// exports.default = g;

import BossCommingUIBindings from "./BossComming_UIBindings";
import ResKeeper from "./ResKeeper";
import { AudioMgr } from "./AudioManager";
import { BundleNames } from "./BundleConfig";

const { ccclass, property, inspector } = cc._decorator;

/**
 * BossComming 类
 * 建议名称：BossCommingComponent
 */
@ccclass
class BossCommingComponent extends ResKeeper {
    
    /**
     * 自动UI绑定
     * 建议名称：autoUI
     */
    @property(BossCommingUIBindings)
    auto_ui: any = null;

    /**
     * 当组件加载时调用
     * 建议名称：handleOnLoad
     */
    onLoad(): void {
        this.startAnimation();
    }

    /**
     * 开始动画
     * 建议名称：startAnimation
     */
    startAnimation(): void {
        const uiBindings = this.auto_ui;

        // 头部节点动作
        this.runNodeHeadAnimation(uiBindings.node_headNode);

        // 骨头节点动作
        this.runNodeBoneAnimation(uiBindings.node_boneNode);

        // 字节点动作
        this.runNodeZiAnimation(uiBindings.node_ziNode);

        // 火焰节点动作
        this.runNodeFireAnimation(uiBindings.node_fireNode);
    }

    /**
     * 头部节点动画
     * 建议名称：runNodeHeadAnimation
     */
    private runNodeHeadAnimation(headNode: cc.Node): void {
        headNode.runAction(
            cc.repeatForever(
                cc.sequence(
                    cc.spawn(cc.scaleTo(1, 1.1, 1.1), cc.fadeTo(1, 180)),
                    cc.spawn(cc.scaleTo(1, 1, 1), cc.fadeTo(1, 255))
                )
            )
        );
    }

    /**
     * 骨头节点动画
     * 建议名称：runNodeBoneAnimation
     */
    private runNodeBoneAnimation(boneNode: cc.Node): void {
        boneNode.runAction(
            cc.repeatForever(
                cc.sequence(
                    cc.rotateTo(0.125, 15),
                    cc.rotateTo(0.25, -15),
                    cc.rotateTo(0.125, 0),
                    cc.delayTime(1)
                )
            )
        );
    }

    /**
     * 字节点动画
     * 建议名称：runNodeZiAnimation
     */
    private runNodeZiAnimation(ziNode: cc.Node): void {
        ziNode.runAction(
            cc.repeatForever(
                cc.sequence(
                    cc.scaleTo(1, 1.1, 1.1),
                    cc.scaleTo(1, 1, 1)
                )
            )
        );
    }

    /**
     * 火焰节点动画
     * 建议名称：runNodeFireAnimation
     */
    private runNodeFireAnimation(fireNode: cc.Node): void {
        let fireNodeIndex = 0;
        fireNode.runAction(
            cc.repeatForever(
                cc.sequence(
                    cc.callFunc(() => {
                        fireNode.children.forEach((child: cc.Node, index: number) => {
                            child.active = index === fireNodeIndex % fireNode.childrenCount;
                        });
                        fireNodeIndex++;
                    }),
                    cc.delayTime(0.25)
                )
            )
        );
    }

    /**
     * 当组件启用时调用
     * 建议名称：handleOnEnable
     */
    onEnable(): void { }

    /**
     * 当组件禁用时调用
     * 建议名称：handleOnDisable
     */
    onDisable(): void { }

    /**
     * 显示动画
     * 建议名称：displayAnimation
     */
    displayAnimation(): void {
        if (!this.node.children[0].active) {
            AudioMgr.playSoundEffect("sound/bossComming", false, BundleNames.Game);
            this.node.children[0].active = true;

            const tiaoNode = this.auto_ui.node_tiaoNode;
            tiaoNode.setPosition(7, 101);
            tiaoNode.opacity = 255;
            tiaoNode.stopAllActions();
            tiaoNode.runAction(
                cc.sequence(
                    cc.repeat(
                        cc.sequence(
                            cc.moveTo(0.1, tiaoNode.x, tiaoNode.y + 10),
                            cc.moveTo(0.2, tiaoNode.x, tiaoNode.y - 15),
                            cc.moveTo(0.1, tiaoNode.x, tiaoNode.y)
                        ),
                        3
                    ),
                    cc.fadeOut(1),
                    cc.callFunc(() => {
                        this.node.children[0].active = false;
                    })
                )
            );
        }
    }
}

export default BossCommingComponent;